using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Budgetor.Properties;

namespace Budgetor
{
    public partial class FormEditViewEntry : Form
    {
        List<Data> dataCollection;

        public event EventHandler DataAdded;

        public FormEditViewEntry(List<Data> dataCollection)
        {
            InitializeComponent();

            this.dataCollection = dataCollection;
            PopulateDescription();
            PopulateMode();
        }

        private void PopulateMode()
        {
            comboBoxCurrencyType.Items.Add(Resources.Cash);
            comboBoxCurrencyType.Items.Add(Resources.TC);
            comboBoxCurrencyType.Items.Add(Resources.WCC);
        }

        private void PopulateDescription()
        {
            foreach (Data dataItem in dataCollection)
            {
                if (comboBoxDescription.Items.Contains(dataItem.Description))
                    continue;

                comboBoxDescription.Items.Add(dataItem.Description);
            }
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            Data dataItem = new Data();

            dataItem.Date = this.dateTimePicker.Value;
            dataItem.Description = comboBoxDescription.Text;
            dataItem.AmountSpent = (float)numericUpDownAmountSpent.Value;
            dataItem.AmountReimbursed = (float)numericUpDownAmountReimbursed.Value;
            dataItem.CurrencyMode = comboBoxCurrencyType.Text;
            dataItem.DailyAllowance = true;

            dataCollection.Add(dataItem);
            comboBoxDescription.Items.Add(dataItem.Description);

            if (DataAdded != null)
                DataAdded(this, new EventArgs());
        }

        private void OnFocusLeaveFromSpent(object sender, EventArgs e)
        {
            numericUpDownAmountReimbursed.Value = numericUpDownAmountSpent.Value;
        }
    }
}